package com.xuecheng.orders.domain.model.entity;

import cn.hutool.core.lang.Snowflake;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.xuecheng.orders.domain.model.enums.XcOrderStatusEnum;
import com.xuecheng.orders.domain.model.vo.req.OrderCreateCmd;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>
 * 
 * </p>
 *
 * @author itcast
 */
@Data
@TableName("xc_orders")
public class XcOrders implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 订单号
     */
    private Long id;

    /**
     * 总价
     */
    private Float totalPrice;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createDate;

    /**
     * 交易状态
     */
    private String status;

    /**
     * 用户id
     */
    private String userId;

    /**
     * 订单类型
     */
    private String orderType;

    /**
     * 订单名称
     */
    private String orderName;

    /**
     * 订单描述
     */
    private String orderDescrip;

    /**
     * 订单明细json
     */
    private String orderDetail;

    /**
     * 外部系统业务id
     */
    private String outBusinessId;


    public static XcOrders buildByRequest(Long userId, OrderCreateCmd orderCreateCmd) {
        XcOrders xcOrders = new XcOrders();
        xcOrders.setId(new Snowflake().nextId());
        xcOrders.setTotalPrice(orderCreateCmd.getTotalPrice());
        xcOrders.setCreateDate(LocalDateTime.now());
        xcOrders.setStatus(XcOrderStatusEnum.WAIT.getCode());
        xcOrders.setUserId(userId.toString());
        xcOrders.setOrderType(orderCreateCmd.getOrderType());
        xcOrders.setOrderName(orderCreateCmd.getOrderName());
        xcOrders.setOrderDescrip(orderCreateCmd.getOrderDescrip());
        xcOrders.setOrderDetail(orderCreateCmd.getOrderDetail());
        xcOrders.setOutBusinessId(orderCreateCmd.getOutBusinessId().toString());

        return xcOrders;
    }
}
